<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">
    <!-- 下拉框 -->
    <link rel="stylesheet" href="static/ace/css/chosen.css"/>

    <link href="plugins/kindeditor/themes/simple/simple.css" type="text/css" rel="stylesheet">
    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
</head>
<body class="no-skin">
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="row">
                    <div class="col-xs-12">
                        <form action="verion/${msg}.do" name="versionForm" id="versionForm" method="post"
                              enctype="multipart/form-data">
                            <c:if test="${version.id != null }">
                                <input type="hidden" name="id" id="id" value="${version.id }"/>
                            </c:if>
                            <div id="zhongxin" style="padding-top: 13px;">
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">app版本名:</td>
                                        <td><input type="text" name="name" id="name"
                                                   value="${version.app_version_name }" placeholder="这里输入app版本名"
                                                   title="app版本名" style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">app版本号:</td>
                                        <td><input type="text" name="code" id="code"
                                                   value="${version.app_version_code }" placeholder="这里输入app版本号"
                                                   title="app版本号" style="width:98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">app描述:</td>
                                        <td>
                                            <textarea style="width:98%;height:300px;" name="describe"
                                                      id="describe">${version.app_describe}</textarea>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">app下载地址:</td>
                                        <td>
                                            <span><input id="fruit" type="checkbox"/>上传</span>
                                            <input name="upload1" id="upload1" type="hidden" value=""/>
                                            <input class="span10" name="apkUrl" id="apkUrl" value="${version.apk_url }"
                                                   type="text" style="width:90%;" placeholder="app下载地址,点击选框上传下载地址"
                                                   title="app下载地址"/>
                                            <div class="files" style="display:none">
                                                <input style="display:none" type="file" name="pic"
                                                       onchange="PreviewImage(this)" id="upload"/>
                                                <label class="uploadBtn btn btn-success" for="upload">上传文件</label>
                                                <c:if test="${version.apk_url != null}">
                                                    <div class="preview"><img class="previewImg"
                                                                              src="${version.apk_url}"><span
                                                            class="dib__vm"></span></div>
                                                </c:if>
                                                <c:if test="${version.apk_url == null}">
                                                    <div class="preview" style="display:none"><img class="previewImg"
                                                                                                   src="${version.apk_url}"><span
                                                            class="dib__vm"></span></div>
                                                </c:if>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">日期:</td>
                                        <td>
                                            <input class="dib vm" name="date" id="date" value="${version.app_date }"
                                                   type="text" readonly="readonly" style="width:98%;" placeholder="日期"
                                                   title="日期"
                                                   onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"/>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:79px;text-align: right;padding-top: 13px;">类型:</td>
                                        <td>
                                            <select class="dib vm" name="type" id="type" style="width:98%;">
                                                <c:if test="${version.app_type=='iOS'||empty version.app_type}">
                                                    <option value="iOS" selected="selected">iOS</option>
                                                    <option value="Android">Android</option>
                                                </c:if>
                                                <c:if test="${version.app_type=='Android'}">
                                                    <option value="iOS">iOS</option>
                                                    <option value="Android" selected="selected">Android</option>
                                                </c:if>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width:100px;text-align: right;padding-top: 13px;">是否强推:</td>
                                        <td>
                                        <input type="hidden" name="isPush"  id="isPush" value="${version.is_push}"/>
                                            <span><input name="isPushs" id="isPushs1" type="radio" value="01"/>是 </span>&nbsp;|&nbsp;
                                            <span><input name="isPushs" id="isPushs2" type="radio" value="00" checked="checked"/>否 </span>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="text-align: center;" colspan="10">
                                            <a class="btn btn-mini btn-primary" onclick="save();">保存</a>
                                            <a class="btn btn-mini btn-danger" onclick="top.Dialog.close();">取消</a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div id="zhongxin2" class="center" style="display:none"><br/><br/><br/><br/><img
                                    src="static/images/jiazai.gif"/><br/><h4 class="lighter block green"></h4></div>
                        </form>
                    </div>
                    <!-- /.col -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.page-content -->
        </div>
    </div>
    <!-- /.main-content -->
</div>
<!-- /.main-container -->
<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!-- inline scripts related to this page -->
<!-- 下拉框 -->
<script src="static/ace/js/chosen.jquery.js"></script>
<!-- 日期时间控件 -->
<script src="static/laydate/laydate.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<script type="text/javascript" src="static/js/common/file_upload.js"></script>
<script type="text/javascript" src="plugins/kindeditor/kindeditor-all.js"></script>
<script type="text/javascript" src="plugins/kindeditor/lang/zh_CN.js"></script>

</body>
<script type="text/javascript">
    $(top.hangge());
    $(function () {
        //日期框
        $('date-picker').datepicker({autoclose: true, todayHighlight: true});
        $("#apkUrl").show();
        if ($("#isPush").val() == '00') {
            $("#isPushs2").attr("checked", true);
        } else {
            $("#isPushs1").attr("checked", true);
        }
    });

    $("#fruit").change(function () {
        if ($("#fruit").is(":checked")) {
            $("#apkUrl").hide();
            $(".files").show();
        } else {
            $("#apkUrl").show();
            $(".files").hide()
        }
    });

    function save() {
        if ($.trim($("#name").val()) == "") {
            alert("app版本名不能为空");
            return false;
        }
        if ($.trim($("#code").val()) == "") {
            alert("app版本号不能为空");
            return false;
        }
        if ($.trim($("#describe").val()) == "") {
            alert("app描述不能为空");
            return false;
        }
        if ($.trim($("#date").val()) == "") {
            alert("日期不能为空");
            return false;
        }
        if ($("#fruit").is(":checked")) {
            $("#upload1").val("01")
            if ($.trim($("#upload").val()) == "") {
                alert("请选择文件!");
                return false;
            }
        }
        var isPush = $("input[name='isPushs']:checked").val();
        $("#isPush").val(isPush);
        $("#versionForm").submit();
        $("#zhongxin").hide();
        $("#zhongxin2").show();
    }

    function PreviewImage(imgFile) {
        var files = imgFile.files[0]
        var read = new FileReader();
        var parent = imgFile.parentNode

        read.readAsDataURL(files)

        read.onload = function () {
            var base = this.result;
            var preview = parent.querySelector('.preview');
            var nImg = parent.querySelector('.previewImg')
            nImg.src = base;
            preview.style.display = "block";
        }
    }
</script>
</html>